//
//  OosImageSize.m
//  Oos4ios
//
//  Created by Pablo Gonzalez on 3/17/11.
//  Copyright 2011 11870.com. All rights reserved.
//

#import <oos4ios/Model/OosImageSize.h>
#import "../../Macros/EnumMacros.h"
#import "../../Utils/OosEnum+Internal.h"

@implementation OosImageSize

OosEnumValues(imageSize, @"small", @"medium", 
			  @"large", @"extra");

OosEnumDictionary(imageSize);

OosEnumGetter(OosImageSize *, small, OOS_IMAGE_SIZE_SMALL);
OosEnumGetter(OosImageSize *, medium, OOS_IMAGE_SIZE_MEDIUM);
OosEnumGetter(OosImageSize *, large, OOS_IMAGE_SIZE_LARGE);
OosEnumGetter(OosImageSize *, extra, OOS_IMAGE_SIZE_EXTRA);

static NSArray *prefixes;

- (NSString *) pathFromPath:(NSString *)original
{
	if (!prefixes) {
		prefixes = [[NSArray alloc] initWithObjects: @"ps", @"pm", @"pl", @"pxl", nil];
	}
	NSString *targetPrefix = [prefixes objectAtIndex: [self ordinal]];
	if ([original rangeOfString: targetPrefix].location == NSNotFound) {
		for (NSString *prefix in prefixes) {
			if ([original rangeOfString: prefix].location != NSNotFound) {
				return [original stringByReplacingOccurrencesOfString:prefix 
														   withString:targetPrefix];
			}
		}
	}
	return original;
}

@end
